<script setup name="sparerequire">
import addForm from './addForm.vue'
import plan from './plan.vue'
import { GetPrintingAPI } from '@/api/warehouse/incomingPrint/pring'
// 表格加载状态
const loading = ref(false)

// 新增弹窗状态
const addIsShow = ref(false)

// title
const title = ref('新增')

const rightText = ref('')

// tabs默认值
const activeName = ref('1')

//备件采购需求  表格数据
const TableData = ref([
  {
    a: ''
  }
])

// 列表总数量
const total = ref(0)

// 表单
const ruleForm = reactive({})

// 查询条件
const SelectList = ref([
  { type: '日期范围' },
  { label: '采购需求单号', model: 'a', type: '输入框' },
  { label: '备件名称', model: 'a', type: '输入框' },
  { label: '单据状态', model: 'a', type: '输入框' },
  { label: '需求部门', model: 'a', type: '下拉单选', opt: [] }
])

// 查询条件
const query = reactive({
  pageNum: 1,
  pageSize: 10
})

// 添加单据弹窗
const addDia = () => {
  title.value = '新增'
  addIsShow.value = true
}

// 计划下达弹窗
const planDia = () => {
  title.value = '计划下达'
  addIsShow.value = true
}

// 关闭弹窗
const close = () => {
  addIsShow.value = false
}

// 条件查询
const selectSubmit = Obj => {
  for (let KEY in Obj) {
    query[KEY] = Obj[KEY]
  }
  getList()
}

// 获取列表
const getList = async () => {
  loading.value = true
  try {
    const res = await GetPrintingAPI(query)
    TableData.value = res.rows
    total.value = res.total
  } catch (error) {
  } finally {
    loading.value = false
  }
}
// getList()
</script>

<template>
  <div class="app-container">
    <!-- 查询条件组件 -->
    <SelectForm :SelectForm="SelectList" @selectSubmit="selectSubmit" />
    <el-card class="box-card">
      <div class="btnmp">
        <el-button type="primary" v-hasPermi="['spareadmin:admin:sparerequire:add']" @click="addDia"
          >添加单据</el-button
        >
        <el-button
          type="primary"
          v-hasPermi="['spareadmin:admin:sparerequire:subexamine']"
          :disabled="delDisabled"
          @click="smallRollDia"
          >提交审核</el-button
        >
        <el-button
          type="primary"
          v-hasPermi="['spareadmin:admin:sparerequire:outexamine']"
          :disabled="delDisabled"
          @click="smallRollDia"
          >撤销审核</el-button
        >
        <el-button
          type="primary"
          v-hasPermi="['spareadmin:admin:sparerequire:examinedata']"
          :disabled="delDisabled"
          @click="smallRollDia"
          >审核单据</el-button
        >
        <el-button
          type="primary"
          v-hasPermi="['spareadmin:admin:sparerequire:closedata']"
          :disabled="delDisabled"
          @click="smallRollDia"
          >关结单据</el-button
        >
        <el-button
          type="primary"
          v-hasPermi="['spareadmin:admin:sparerequire:remove']"
          :disabled="delDisabled"
          @click="smallRollDia"
          >删除</el-button
        >
        <el-button
          type="primary"
          v-hasPermi="['spareadmin:admin:sparerequire:plan']"
          :disabled="delDisabled"
          @click="planDia"
          >计划下达</el-button
        >
        <el-button
          type="primary"
          v-hasPermi="['spareadmin:admin:sparerequire:withdraw']"
          :disabled="delDisabled"
          @click="smallRollDia"
          >撤回</el-button
        >
        <el-button
          type="primary"
          v-hasPermi="['spareadmin:admin:sparerequire:plansure']"
          :disabled="delDisabled"
          @click="smallRollDia"
          >计划确认</el-button
        >
      </div>
      <el-table v-loading="loading" stripe border :data="TableData" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" fixed="left" />
        <el-table-column label="序号" width="70" type="index" />
        <el-table-column label="采购需求单号" prop="a" width="220" />
        <el-table-column label="单据状态" align="center" width="220">
          <template #default="scope">
            <div>
              <p-tag bgc="#8273b8" text="待下达" />
              <p-tag bgc="#fd0013" text="未通过" />
              <p-tag bgc="#b6b6b6" text="已完成" />
              <p-tag bgc="#8f8f8f" text="已关结" />
              <p-tag bgc="#0663aa" text="待提交" />
              <p-tag bgc="#fabf3c" text="待审核" />
              <p-tag bgc="#ef8127" text="审核中" />
              <p-tag bgc="#4d3ecc" text="下达中" />
            </div>
          </template>
        </el-table-column>
        <el-table-column label="备件名称" prop="documentTypeDict" width="180" />
        <el-table-column label="备件编码" prop="supplierName" width="180" />
        <el-table-column label="计划数量" prop="quantityBatch" width="180" :show-overflow-tooltip="true" />
        <el-table-column label="备件单位" prop="printedQuantity" width="180" />
        <el-table-column label="需求时间" prop="createBy" width="180" />
        <el-table-column label="需求人" prop="createTime" width="220" />
        <el-table-column label="需求部门" prop="printBy" width="180" />
        <el-table-column label="开单时间" prop="printTime" width="220" />
        <el-table-column label="审核人" prop="printTime" width="220" />
        <el-table-column label="审核时间" prop="printTime" width="220" />
        <el-table-column label="操作" align="center" width="120" fixed="right" class-name="small-padding fixed-width">
          <template #default="scope">
            <div>
              <el-link
                type="primary"
                text="修改"
                v-hasPermi="['spareadmin:admin:sparerequire:edit']"
                @click="printFn(scope.row.productionId)"
              />
              <el-link
                type="primary"
                text="删除"
                v-hasPermi="['spareadmin:admin:sparerequire:remove']"
                @click="printFn(scope.row.productionId)"
              />
              <el-link
                type="primary"
                text="查看"
                v-hasPermi="['spareadmin:admin:sparerequire:query']"
                @click="printFn(scope.row.productionId)"
              />
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="query.pageNum"
        v-model:limit="query.pageSize"
        @pagination="getList"
      />
      <el-tabs v-model="activeName" class="demo-tabs" @tab-change="handleClick">
        <el-tab-pane label="单据明细" name="1"></el-tab-pane>
        <el-table v-loading="loading" stripe border :data="eetableData" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" fixed="left" />
          <el-table-column label="序号" width="70" type="index" align="center" />
          <el-table-column label="采购需求单号" align="center" prop="wodDocNum" width="120"> </el-table-column>
          <el-table-column label="单据状态" align="center" width="auto" prop="wodStatus">
            <template #default="scope">
              <div>
                <p-tag bgc="#28c6af" text="预下单" />
                <p-tag bgc="#3197d2" text="待到货" />
                <p-tag bgc="#3197d2" text="部分到货" />
                <p-tag bgc="#b6b6b6" text="已完成" />
                <p-tag bgc="#8f8f8f" text="已关结" />
                <p-tag bgc="#8273b8" text="待下单" />
              </div>
            </template>
          </el-table-column>
          <el-table-column label="备件名称" align="center" prop="wodDocNum" width="120"> </el-table-column>
          <el-table-column label="备件编码" align="center" width="auto" prop="wodStatus" />
          <el-table-column label="备件单位" prop="connectionId" width="120" align="center" />
          <el-table-column
            label="计划数量"
            prop="dateDelivery"
            width="180"
            :show-overflow-tooltip="true"
            align="center"
          />
          <el-table-column label="下达数量" prop="materialCode" width="100" align="center" />
          <el-table-column label="计划单价" prop="itemName" width="auto" align="center" />
          <el-table-column label="需求时间" prop="itemName" width="auto" align="center" />
        </el-table>
      </el-tabs>
    </el-card>

    <p-XiaoheDialog :dialogVisible="addIsShow" :title="title" @close="close" width="50%">
      <template #body>
        <addForm v-if="title == '新增'" />
        <plan v-if="title == '计划下达'" />
        <Btn :loading="Btnloading" @close="close" @submit="title == '新增' ? addSub() : editSub()" />
      </template>
    </p-XiaoheDialog>
  </div>
</template>
<style lang="scss" scoped>
.btnmp {
  margin-bottom: 20px;
}
</style>
